package com.walterweimod.auxiliary_attributes.event;

import com.walterweimod.auxiliary_attributes.attribute.ModAttributes;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeMap;
import net.minecraftforge.event.entity.living.LivingHealEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.Objects;

import static com.walterweimod.auxiliary_attributes.Auxiliary_attributes.*;

@Mod.EventBusSubscriber
public class HealChangeEvent {
    @SubscribeEvent(priority = EventPriority.LOW)
    public static void onLivingEntityHeal(LivingHealEvent livingHealEvent){
        LivingEntity livingEntity = livingHealEvent.getEntityLiving();
        float amount = livingHealEvent.getAmount();
        AttributeMap attributeMap = livingEntity.getAttributes();
        AttributeInstance heal_bonus = attributeMap.getInstance(ModAttributes.HEAL_BONUS.get());
        AttributeInstance heal_boost = attributeMap.getInstance(ModAttributes.HEAL_BOOST.get());

        if (amount > 0.0F && Objects.nonNull(heal_boost) && Objects.nonNull(heal_bonus)){
            getLogger().info("正在治疗，目前治疗量提升：{}", heal_boost.getValue());
            getLogger().info("正在治疗，目前治疗量加成：{}", heal_bonus.getValue());

            livingHealEvent.setAmount(
                    (amount + (float) heal_boost.getValue()) * (float) heal_bonus.getValue()
            );

            getLogger().info("基础治疗量为：{}", amount);
            getLogger().info(
                    "总治疗量为：{}",
                    (amount + (float) heal_boost.getValue()) * (float) heal_bonus.getValue()
            );
        }
    }
}
